using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

namespace MessageBoxProject
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string msg = "Are you sure to delete file name";
            if (MessageBox.Show(msg + " 'C:\\" 
                + lvData.FocusedItem.Text + "'", "C#2005",
                MessageBoxButtons.YesNoCancel,
                MessageBoxIcon.Warning,
                MessageBoxDefaultButton.Button3) == DialogResult.Yes)
            {
                File.Delete("C:\\" + lvData.FocusedItem.Text);
                ShowFile();
            }
        }

        private void Form3_Load(object sender, EventArgs e)
        {
            ShowFile();
        }
        void ShowFile()
        {
            try
            {
                lvData.Items.Clear();
                DirectoryInfo dir = new DirectoryInfo("C:\\");
                lvData.Columns.Add("Name", 100, 0);
                lvData.Columns.Add("Size", 50, 0);
                lvData.Columns.Add("Date", 70, 0);
                lvData.View = View.Details;
                ListViewItem item1;
                foreach (FileInfo d in dir.GetFiles("*.*"))
                {
                    item1 = new ListViewItem(d.Name);
                    item1.SubItems.Add(d.Length.ToString());
                    item1.SubItems.Add(d.CreationTime.ToLongDateString());
                    lvData.Items.Add(item1);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}